package com.xiaov.android.games.my3d;

import javax.microedition.khronos.opengles.GL10;
import android.graphics.Bitmap;
import com.xiaov.android.games.my3d.mesh.SimplePlane;
import com.xiaov.brilliard.Data;
import com.xiaov.math.Vector3D;

public class Board {

	float width = 150;
	float height = 150;
	float x = -300 ;
	float y = 150;
	float z = 100;
	
	SimplePlane d;
	SimplePlane over;
	
	boolean shouldDisplay = false;
	
	public Board(){
		d = new SimplePlane(width, height);
		over = new SimplePlane(width / 30, height / 30);
		d.x = x;
		d.y = y;
		d.z = z;
		over.x = x;
		over.y = y;
		over.z = z + 1.5f;
	}
	
	public Board(float x, float y, float width, float height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		d = new SimplePlane(width, height);
		over = new SimplePlane(width / 30, height / 30);
		d.x = x;
		d.y = y;
		d.z = z;
		over.x = x;
		over.y = y;
		over.z = z + 0.5f;
	}



	public void bindBitmap(Bitmap bitmap1, Bitmap bitmap2){
		d.loadBitmap(bitmap1);
		over.loadBitmap(bitmap2);
	}
	
	public Vector3D getOffset(){
		return new Vector3D(over.x - x, over.y - y);
	}
	
	public int getOffsetX(){
		return (int)((over.x - x) / width * Data.banjin * 2);
	}
	
	public int getOffsetY(){
		return (int)((over.y - y) / width * Data.banjin * 2);
	}
	
	public void setOffset(float ox, float oy){
		
		float xx = over.x + ox - x;
		float yy = over.y + oy - y;
		if(xx * xx + yy * yy > width * width * 0.25){
			return;
		}
		
		over.x += ox;
		over.y += oy;
	}
	
	public void resetOffset(){
		over.x = x;
		over.y = y;
	}
	
	public void draw(GL10 gl){
		if(shouldDisplay){
			d.draw(gl);
			over.draw(gl);
		}
	}
	
	public void display(){
		shouldDisplay = true;
	}
	
	public void hidden(){
		shouldDisplay = false;
	}
}
